using System;
using System.Collections.Generic;
using System.Text;
using System.Management.Automation;
using System.Collections;
using System.IO;

namespace YaTools.Yaml
{
    [Cmdlet(VerbsData.ConvertTo, "YAML")]
    public class ConvertToYamlCommand : YamlWriterCommand
    {
        [Parameter( ValueFromPipeline=true, Mandatory=true, 
            ValueFromPipelineByPropertyName=true, Position=0)]
        public PSObject InputObject { get; set; }

 
        protected override void ProcessRecord()
        {
            try
            {
                if (InputObject != null)
                {
                    using (var writer = new StringWriter())
                    {
                        var dumper = new Dump(new Dump.Presenter.Yaml.Explicit());

                        // TODO: better options control: Work item 9842.

                        dumper.Serialize(writer,InputObject);
                        WriteObject(writer.ToString());
                    }
                }
            }
            catch (ApplicationException)
            {
                throw;
            }
        }
    }
}
